//
//  LHUserViewController.m
//  Knight_Tour
//
//  Created by Bruce_Lin on 15/5/13.
//  Copyright (c) 2015年 TouchOne. All rights reserved.
//

#import "LHUserViewController.h"
#import "LHUserVIew.h"
#import "LHUserRecommendSightDetailViewController.h"
#import "LHCollectDetailViewController.h"
#import "LHTouristDetailViewController.h"
#import "LHHotelDetailViewController.h"
#import "LHRestaurantDetailViewController.h"
#import "LHClearViewController.h"
#import "MyNavgationView.h"
#import "SDImageCache.h"
#import "SDWebImageManager.h"


@interface LHUserViewController ()<jumpToDetailPageDelegate, UIAlertViewDelegate>
@property (nonatomic, retain) LHUserVIew *userTableView;

@end

@implementation LHUserViewController
- (void)dealloc
{
    [_userTableView release];
    [super dealloc];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationController.navigationBarHidden = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self createTableView];

    [self creatTitle];
}

- (void)creatTitle
{
    MyNavgationView *myNV = [[MyNavgationView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];

    self.navigationController.navigationBar.translucent = NO;
    [myNV creatTitle:@"用户"];
    [self.view addSubview:myNV];
    [myNV release];
}

// 创建TableView
- (void)createTableView
{
    self.userTableView = [[LHUserVIew alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64)];
    _userTableView.delegate = self;
    [self.view addSubview:_userTableView];
    [_userTableView release];
}

- (void)jumpToDetailPage:(NSIndexPath *)indexPath
{
    if (indexPath.row == 6) {
        
        UIAlertView *alv = [[UIAlertView alloc] initWithTitle:@"关于我们" message:@"蒋林亨,庞魁,杜莹莹" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [self.view addSubview:alv];
        [alv show];
        [alv release];
        
    } else if (indexPath.row == 0){
        LHCollectDetailViewController *CDVC = [[LHCollectDetailViewController alloc] init];
        [CDVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:CDVC animated:YES];
        [CDVC release];

    } else if (indexPath.row == 1){
        LHTouristDetailViewController *TDVC = [[LHTouristDetailViewController alloc] init];
        [TDVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:TDVC animated:YES];
        [TDVC release];
        
    } else if (indexPath.row == 2){
        LHUserRecommendSightDetailViewController *RSDVC = [[LHUserRecommendSightDetailViewController alloc] init];
        [RSDVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:RSDVC animated:YES];
        [RSDVC release];
        
    } else if (indexPath.row == 3){
        LHHotelDetailViewController *HDVC = [[LHHotelDetailViewController alloc] init];
        [HDVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:HDVC animated:YES];
        [HDVC release];
        
    } else if (indexPath.row == 4){
        LHRestaurantDetailViewController *RDVC = [[LHRestaurantDetailViewController alloc] init];
        [RDVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:RDVC animated:YES];
        [RDVC release];
        
    } else if (indexPath.row == 5){
        [self clear];
    }
}

- (void)clear
{
    float tmpSize = [[SDImageCache sharedImageCache] getSize];
    NSString *clearCacheName = tmpSize >= 1024 * 1024 ? [NSString stringWithFormat:@"清理缓存(%.2fM)" , tmpSize / 1024 / 1024] : [NSString stringWithFormat:@"清理缓存(%.2fK)", tmpSize / 1024];

    UIAlertView *alv1 = [[UIAlertView alloc] initWithTitle:@"清除缓存" message:clearCacheName delegate:self cancelButtonTitle:@"清除缓存" otherButtonTitles:@"取消", nil];
    [alv1 show];
    [alv1 release];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        [[SDImageCache sharedImageCache]clearDisk];
        //清除内存缓存
        [[[SDWebImageManager sharedManager] imageCache] clearMemory];
        //清除系统缓存
        [[NSURLCache sharedURLCache] removeAllCachedResponses];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
